home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / EmacsManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-25  |  8.0 KB  |  255 lines

  1. /* Emacs manager widget.
  2.    Copyright (C) 1994 Sun Microsystems, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* Written by Ben Wing, May, 1994. */
  23.  
  24. #include <config.h>
  25.  
  26. #include <X11/StringDefs.h>
  27. #include "EmacsManagerP.h"
  28. #ifdef LWLIB_MENUBARS_MOTIF
  29. #include <Xm/RowColumn.h>
  30. #endif /* LWLIB_MENUBARS_MOTIF */
  31.  
  32. /* For I, Emacs, am a kind god.  Unlike the goddess Athena and the
  33.    Titan Motif, I require no ritual sacrifices to placate the lesser
  34.    daemons of geometry management. */
  35.  
  36. static XtResource resources[] = {
  37. #define offset(field) XtOffset(EmacsManagerWidget, emacs_manager.field)
  38.   { XtNresizeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  39.       offset(resize_callback), XtRImmediate, (XtPointer) 0 },
  40.   { XtNqueryGeometryCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  41.       offset(query_geometry_callback), XtRImmediate, (XtPointer) 0 },
  42.   { XtNuserData, XtCUserData, XtRPointer, sizeof(XtPointer),
  43.       offset(user_data), XtRImmediate, (XtPointer) 0 },
  44. };
  45.  
  46. /****************************************************************
  47.  *
  48.  * Full class record constant
  49.  *
  50.  ****************************************************************/
  51.  
  52. static XtGeometryResult QueryGeometry (Widget wid,
  53.                        XtWidgetGeometry *request,
  54.                        XtWidgetGeometry *reply);
  55. static void Resize (Widget w);
  56. static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request,
  57.                      XtWidgetGeometry *reply);
  58. static void ChangeManaged (Widget w);
  59. static void Realize (Widget w, Mask *valueMask,
  60.              XSetWindowAttributes *attributes);
  61. static void ClassInitialize (void);
  62.  
  63. EmacsManagerClassRec emacsManagerClassRec = {
  64.   {
  65. /* core_class fields      */
  66. #ifdef LWLIB_USES_MOTIF
  67.     /* superclass         */    (WidgetClass) &xmManagerClassRec,
  68. #else
  69.     /* superclass         */    (WidgetClass) &compositeClassRec,
  70. #endif
  71.     /* class_name         */    "EmacsManager",
  72.     /* widget_size        */    sizeof(EmacsManagerRec),
  73.     /* class_initialize   */    ClassInitialize,
  74.     /* class_part_init    */    NULL,
  75.     /* class_inited       */    FALSE,
  76.     /* initialize         */    NULL,
  77.     /* initialize_hook    */    NULL,
  78.     /* realize            */    Realize,
  79.     /* actions            */    NULL,
  80.     /* num_actions      */    0,
  81.     /* resources          */    resources,
  82.     /* num_resources      */    XtNumber(resources),
  83.     /* xrm_class          */    NULLQUARK,
  84.     /* compress_motion      */    TRUE,
  85.     /* compress_exposure  */    TRUE,
  86.     /* compress_enterleave*/    TRUE,
  87.     /* visible_interest   */    FALSE,
  88.     /* destroy            */    NULL,
  89.     /* resize             */    Resize,
  90.     /* expose             */    NULL,
  91.     /* set_values         */    NULL,
  92.     /* set_values_hook    */    NULL,
  93.     /* set_values_almost  */    XtInheritSetValuesAlmost,
  94.     /* get_values_hook    */    NULL,
  95.     /* accept_focus       */    NULL,
  96.     /* version            */    XtVersion,
  97.     /* callback_private   */    NULL,
  98.     /* tm_table           */    XtInheritTranslations,
  99.     /* query_geometry     */    QueryGeometry,
  100.     /* display_accelerator*/    XtInheritDisplayAccelerator,
  101.     /* extension          */    NULL
  102.   },
  103.   {
  104. /* composite_class fields */
  105.     /* geometry_manager   */    GeometryManager,
  106.     /* change_managed     */    ChangeManaged,
  107.     /* insert_child      */    XtInheritInsertChild,
  108.     /* delete_child      */    XtInheritDeleteChild,
  109.     /* extension          */    NULL
  110.   },
  111. #ifdef LWLIB_USES_MOTIF
  112.   {
  113.   /* constraint_class fields */
  114.       NULL,                                     /* resource list        */   
  115.       0,                                        /* num resources        */   
  116.       0,                                        /* constraint size      */   
  117.       (XtInitProc)NULL,                         /* init proc            */   
  118.       (XtWidgetProc)NULL,                       /* destroy proc         */   
  119.       (XtSetValuesFunc)NULL,                    /* set values proc      */   
  120.       NULL,                                     /* extension            */
  121.   },
  122.   {
  123. /* manager_class fields */
  124.     XtInheritTranslations,            /* translations           */
  125.     NULL,                    /* syn_resources            */
  126.     0,                        /* num_syn_resources       */
  127.     NULL,                    /* syn_cont_resources     */
  128.     0,                        /* num_syn_cont_resources */
  129.     XmInheritParentProcess,            /* parent_process         */
  130.     NULL,                    /* extension                 */
  131.   },
  132. #endif
  133.   {
  134. /* emacs_manager_class fields */
  135.     /* empty          */    0,
  136.   }
  137. };
  138.  
  139. WidgetClass emacsManagerWidgetClass = (WidgetClass)&emacsManagerClassRec;
  140.  
  141. /* What is my preferred size?  A suggested size may be given. */
  142.  
  143. static XtGeometryResult
  144. QueryGeometry (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
  145. {
  146.   EmacsManagerWidget emw = (EmacsManagerWidget) w;
  147.   EmacsManagerQueryGeometryStruct struc;
  148.   int mask = request->request_mode & (CWWidth | CWHeight);
  149.  
  150.   struc.request_mode = mask;
  151.   struc.proposed_width = request->width;
  152.   struc.proposed_height = request->height;
  153.   XtCallCallbackList (w, emw->emacs_manager.query_geometry_callback, &struc);
  154.   reply->request_mode = CWWidth | CWHeight;
  155.   reply->width = struc.proposed_width;
  156.   reply->height = struc.proposed_height;
  157.   if (((mask & CWWidth) && (request->width != reply->width))
  158.       || ((mask & CWHeight) && (request->height != reply->height)))
  159.     return XtGeometryAlmost;
  160.   return XtGeometryYes;
  161. }
  162.  
  163. static void
  164. Resize (Widget w)
  165. {
  166.   EmacsManagerWidget emw = (EmacsManagerWidget) w;
  167.   EmacsManagerResizeStruct struc;
  168.  
  169.   struc.width = w->core.width;
  170.   struc.height = w->core.height;
  171.   XtCallCallbackList (w, emw->emacs_manager.resize_callback, &struc);
  172. }
  173.  
  174. static XtGeometryResult
  175. GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
  176. {
  177.   /* Sure, any changes are fine. */
  178. #define COPY(field, mask) \
  179.   if (request->request_mode & mask) w->core.field = request->field
  180.  
  181.   /* The Motif menubar will merrily request a new size every time a
  182.      child is added or deleted.  Blow it off because it doesn't know
  183.      what it's talking about. */
  184. #ifdef LWLIB_MENUBARS_MOTIF
  185.   if (!(XtClass (w) == xmRowColumnWidgetClass))
  186. #endif /* LWLIB_MENUBARS_MOTIF */
  187.     {
  188.       COPY (width, CWWidth);
  189.       COPY (height, CWHeight);
  190.     }
  191.   COPY (border_width, CWBorderWidth);
  192.   COPY (x, CWX);
  193.   COPY (y, CWY);
  194. #undef COPY
  195.  
  196.   return XtGeometryYes;
  197. }
  198.  
  199. static void
  200. ChangeManaged (Widget w)
  201. {
  202.   if (!XtIsRealized (w))
  203.     {
  204.       XtWidgetGeometry req, repl;
  205.  
  206.       /* find out how big we'd like to be ... */
  207.  
  208.       req.request_mode = 0;
  209.       XtQueryGeometry (w, &req, &repl);
  210.       EmacsManagerChangeSize (w, repl.width, repl.height);
  211.     }
  212. }
  213.  
  214. static void
  215. Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
  216. {
  217.   attributes->bit_gravity = NorthWestGravity;
  218.   *valueMask |= CWBitGravity;
  219.   
  220.   XtCreateWindow (w, (unsigned) InputOutput, (Visual *) CopyFromParent,
  221.           *valueMask, attributes);
  222. }
  223.  
  224. static void
  225. ClassInitialize (void)
  226. {
  227.   return;
  228. }
  229.  
  230. void
  231. EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
  232. {
  233.   Dimension realwidth, realheight;
  234.   XtGeometryResult res;
  235.  
  236.   if (width == 0)
  237.     width = w->core.width;
  238.   if (height == 0)
  239.     height = w->core.height;
  240.  
  241.   /* do nothing if we're already that size */
  242.   if (w->core.width != width || w->core.height != height)
  243.     {
  244.       res = XtMakeResizeRequest (w, width, height, &realwidth, &realheight);
  245.       if (res == XtGeometryAlmost)
  246.     XtMakeResizeRequest (w, realwidth, realheight, NULL, NULL);
  247.       w->core.width = realwidth;
  248.       w->core.height = realheight;
  249.     }
  250.  
  251.   Resize (w);
  252. }
  253.  
  254.  
  255.